/*
 * cadProdutoJInternalFrame.java
 *
 * Created on 27/10/2009, 21:03:56
 */
package br.com.fatecpg.zanotti.jframes.cadastros;

import br.com.fatecpg.zanotti.acessobanco.conComboCargo;
import br.com.fatecpg.zanotti.acessobanco.conComboLoja;
import br.com.fatecpg.zanotti.acessobanco.conTableUsuario;
import br.com.fatecpg.zanotti.acessobanco.dmlFuncionario;
import br.com.fatecpg.zanotti.acessobanco.dmlUsuario;
import br.com.fatecpg.zanotti.jframes.consultas.conUsuarioJInternalFrame;
import br.com.fatecpg.zanotti.modelo.Funcionario;
import br.com.fatecpg.zanotti.modelo.Usuario;

/**
 *
 * @author Luiz Zanotti
 */
public class cadUsuarioJInternalFrame extends javax.swing.JInternalFrame {

    /** Creates new form cadProdutoJInternalFrame */
    public cadUsuarioJInternalFrame() {
        initComponents();
        jPanel1.setVisible(false);
        conTableUsuario sac = new conTableUsuario();

        cdfuncjTextField.setText(sac.ConsultaCDFUNCIONARIO());

        conComboLoja con = new conComboLoja();
        String[] teste = con.consulta();
        lojajComboBox.removeAllItems();
        for (int i = 0; i < teste.length; i++) {
            lojajComboBox.addItem(teste[i]);

        }

        conComboCargo con1 = new conComboCargo();
        String[] teste1 = con1.consulta();
        cargojComboBox.removeAllItems();
        for (int i = 0; i < teste1.length; i++) {
            cargojComboBox.addItem(teste1[i]);

        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        cdfuncjTextField = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPasswordField2 = new javax.swing.JPasswordField();
        cadastrarjButton = new javax.swing.JButton();
        lojajLabel = new javax.swing.JLabel();
        lojajComboBox = new javax.swing.JComboBox();
        cargojComboBox = new javax.swing.JComboBox();
        lojajLabel1 = new javax.swing.JLabel();
        nomejLabel = new javax.swing.JLabel();
        nomejTextField = new javax.swing.JTextField();
        cpfjLabel = new javax.swing.JLabel();
        cpfjFormattedTextField = new javax.swing.JFormattedTextField();
        rgjLabel = new javax.swing.JLabel();
        rgjTextField = new javax.swing.JTextField();
        cnhjTextField = new javax.swing.JTextField();
        rgjLabel1 = new javax.swing.JLabel();
        dtnascjLabel = new javax.swing.JLabel();
        datajFormattedTextField = new javax.swing.JFormattedTextField();
        dtnascjLabel1 = new javax.swing.JLabel();
        dataadmjFormattedTextField1 = new javax.swing.JFormattedTextField();
        TelefonejFormattedTextField = new javax.swing.JFormattedTextField();
        teljLabel = new javax.swing.JLabel();
        criarUsrjCheckBox = new javax.swing.JCheckBox();
        selectExistjButton = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("Cadastro de Funcionário");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jPanel1.setEnabled(false);

        jLabel2.setText("Login:");

        cdfuncjTextField.setEnabled(false);

        jPasswordField1.setText("jPasswordField1");

        jLabel3.setText("Senha:");

        jLabel4.setText("Repita a senha:");

        jPasswordField2.setText("jPasswordField1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cdfuncjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                    .addComponent(jPasswordField2, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cdfuncjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        cadastrarjButton.setText("Cadastrar");
        cadastrarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarjButtonActionPerformed(evt);
            }
        });

        lojajLabel.setText("Selecione a Loja:");

        lojajComboBox.setEditable(true);
        lojajComboBox.setFont(new java.awt.Font("Times New Roman", 1, 12));
        lojajComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        lojajComboBox.setToolTipText("Selecione a Loja");
        lojajComboBox.setAutoscrolls(true);
        lojajComboBox.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        lojajComboBox.setDoubleBuffered(true);

        cargojComboBox.setEditable(true);
        cargojComboBox.setFont(new java.awt.Font("Times New Roman", 1, 12));
        cargojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cargojComboBox.setToolTipText("Selecione a Loja");
        cargojComboBox.setAutoscrolls(true);
        cargojComboBox.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cargojComboBox.setDoubleBuffered(true);

        lojajLabel1.setText("Selecione o Cargo:");

        nomejLabel.setText("Nome:");

        cpfjLabel.setText("CPF:");

        cpfjFormattedTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cpfjFormattedTextFieldActionPerformed(evt);
            }
        });

        rgjLabel.setText("RG:");

        rgjTextField.setColumns(12);

        rgjLabel1.setText("CNH:");

        dtnascjLabel.setText("Dt. Nasc:");

        try {
            datajFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        dtnascjLabel1.setText("Dt. Admis.:");

        try {
            dataadmjFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            TelefonejFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        teljLabel.setText("Tel:");

        criarUsrjCheckBox.setText("Criar Usuário");
        criarUsrjCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                criarUsrjCheckBoxActionPerformed(evt);
            }
        });

        selectExistjButton.setText("Selecionar Existente");
        selectExistjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectExistjButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(criarUsrjCheckBox)
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(lojajLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cargojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(lojajLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lojajComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(nomejLabel)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(nomejTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(rgjLabel1)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(cnhjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(dtnascjLabel))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(cpfjLabel)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(cpfjFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(rgjLabel)))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(rgjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                                        .addComponent(datajFormattedTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                                        .addComponent(TelefonejFormattedTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(selectExistjButton)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                                    .addComponent(cadastrarjButton)))
                            .addContainerGap())
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(dtnascjLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(dataadmjFormattedTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(teljLabel)
                            .addGap(129, 129, 129)))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lojajLabel)
                    .addComponent(lojajComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lojajLabel1)
                    .addComponent(cargojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(nomejLabel)
                    .addComponent(nomejTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpfjLabel)
                    .addComponent(cpfjFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rgjLabel)
                    .addComponent(rgjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rgjLabel1)
                    .addComponent(cnhjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dtnascjLabel)
                    .addComponent(datajFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dtnascjLabel1)
                    .addComponent(dataadmjFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(teljLabel)
                    .addComponent(TelefonejFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(criarUsrjCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cadastrarjButton)
                    .addComponent(selectExistjButton))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cpfjFormattedTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cpfjFormattedTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cpfjFormattedTextFieldActionPerformed

    private void criarUsrjCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_criarUsrjCheckBoxActionPerformed
        if (criarUsrjCheckBox.isSelected() == true) {
            jPanel1.setVisible(true);
        } else {
            jPanel1.setVisible(false);
        }
    }//GEN-LAST:event_criarUsrjCheckBoxActionPerformed

    private void selectExistjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectExistjButtonActionPerformed
        conUsuarioJInternalFrame.getInstancia().setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_selectExistjButtonActionPerformed

    private void cadastrarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarjButtonActionPerformed
        Funcionario Funcionario = new Funcionario();

        conComboLoja con = new conComboLoja();
        conComboCargo con1 = new conComboCargo();

        if (rgjTextField.getText().length() > 13) {
            javax.swing.JOptionPane.showMessageDialog(null, "Campo RG com mais digitos que o permitido.");
        } else if (cpfjFormattedTextField.getText().length() > 15) {
            javax.swing.JOptionPane.showMessageDialog(null, "Campo CPF com mais digitos que o permitido.");
        } else {
            Funcionario.setCDCARGO(con1.consultaCDCARGO(cargojComboBox.getSelectedItem().toString()));
            Funcionario.setCDFUNCIONARIO(cdfuncjTextField.getText());
            Funcionario.setCDLOJA(con.consultaCDLOJA(lojajComboBox.getSelectedItem().toString()));
            Funcionario.setCDTELEFONE(TelefonejFormattedTextField.getText().replace("(", "").replace(")", "").replace("-", ""));
            Funcionario.setCNHFUNCIONARIO(cnhjTextField.getText());
            Funcionario.setCPFFUNCIONARIO(cpfjFormattedTextField.getText());
            Funcionario.setDTADMISSAO(dataadmjFormattedTextField1.getText());
            Funcionario.setDTNASCIMENTO(datajFormattedTextField.getText());
            Funcionario.setNMFUNCIONARIO(nomejTextField.getText());
            Funcionario.setRGFUNCIONARIO(rgjTextField.getText());

            boolean b;
            if (cadastrarjButton.getText().equals("Cadastrar")) {
                b = dmlFuncionario.cadastrar(Funcionario);
            } else {

                b = dmlFuncionario.atualizar(Funcionario);
            }


            boolean c = true;
            if (criarUsrjCheckBox.isSelected()) {
                Usuario Usuario = new Usuario();
                conTableUsuario con2 = new conTableUsuario();
                Usuario.setCDFUNCIONARIO(String.valueOf(con2.ConsultaCdfuncMax()));
                Usuario.setCDCARGO(con1.consultaCDCARGO(cargojComboBox.getSelectedItem().toString()));
                Usuario.setCDLOJA(con.consultaCDLOJA(lojajComboBox.getSelectedItem().toString()));


                if (String.valueOf(jPasswordField1.getPassword()).equals(String.valueOf(jPasswordField2.getPassword()))) {
                    Usuario.setCDSENHA(String.valueOf(jPasswordField1.getPassword()));


                    if (cadastrarjButton.getText().equals("Cadastrar")) {
                        c = dmlUsuario.cadastrar(Usuario);
                    } else {

                        c = dmlUsuario.atualizar(Usuario);
                    }

                } else {
                    javax.swing.JOptionPane.showMessageDialog(null, "Senhas não conferem!");
                    jPasswordField1.setText("");
                    jPasswordField2.setText("");
                }



            }
            if (b) {
                resetarValores();
            }
        }
    }//GEN-LAST:event_cadastrarjButtonActionPerformed
    public void resetarValores() {
        jPasswordField1.setText("");
        jPasswordField2.setText("");
        cnhjTextField.setText("");
        TelefonejFormattedTextField.setText("");
        rgjTextField.setText("");
        cpfjFormattedTextField.setText("");
        dataadmjFormattedTextField1.setText("");
        datajFormattedTextField.setText("");
        conTableUsuario con2 = new conTableUsuario();
        cdfuncjTextField.setText(con2.ConsultaCDFUNCIONARIO());
        jPanel1.setVisible(false);
        nomejTextField.setText("");
        criarUsrjCheckBox.setSelected(false);
        lojajComboBox.setSelectedIndex(0);
        cargojComboBox.setSelectedIndex(0);


        cadastrarjButton.setText("Cadastrar");
        this.setTitle("Cadastro de Funcionario");
    }
    private static cadUsuarioJInternalFrame p;

    public static cadUsuarioJInternalFrame getInstancia() {
        if (p == null) {
            p = new cadUsuarioJInternalFrame();
        }
        return p;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField TelefonejFormattedTextField;
    private javax.swing.JButton cadastrarjButton;
    private javax.swing.JComboBox cargojComboBox;
    private javax.swing.JTextField cdfuncjTextField;
    private javax.swing.JTextField cnhjTextField;
    private javax.swing.JFormattedTextField cpfjFormattedTextField;
    private javax.swing.JLabel cpfjLabel;
    private javax.swing.JCheckBox criarUsrjCheckBox;
    private javax.swing.JFormattedTextField dataadmjFormattedTextField1;
    private javax.swing.JFormattedTextField datajFormattedTextField;
    private javax.swing.JLabel dtnascjLabel;
    private javax.swing.JLabel dtnascjLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JPasswordField jPasswordField2;
    private javax.swing.JComboBox lojajComboBox;
    private javax.swing.JLabel lojajLabel;
    private javax.swing.JLabel lojajLabel1;
    private javax.swing.JLabel nomejLabel;
    private javax.swing.JTextField nomejTextField;
    private javax.swing.JLabel rgjLabel;
    private javax.swing.JLabel rgjLabel1;
    private javax.swing.JTextField rgjTextField;
    private javax.swing.JButton selectExistjButton;
    private javax.swing.JLabel teljLabel;
    // End of variables declaration//GEN-END:variables

    public void setCadastrarjButton(String str) {
        cadastrarjButton.setText(str);
    }

    /**
     * @param TelefonejFormattedTextField the TelefonejFormattedTextField to set
     */
    public void setTelefonejFormattedTextField(String str) {
        this.TelefonejFormattedTextField.setText(str);
    }

    /**
     * @param cargojComboBox the cargojComboBox to set
     */
    public void setCargojComboBox(int s) {

        cargojComboBox.setSelectedIndex(s - 1);
    }

    /**
     * @param cdfuncjTextField the cdfuncjTextField to set
     */
    public void setCdfuncjTextField(String str) {
        this.cdfuncjTextField.setText(str);
    }

    /**
     * @param cnhjTextField the cnhjTextField to set
     */
    public void setCnhjTextField(String str) {
        this.cnhjTextField.setText(str);
    }

    /**
     * @param cpfjFormattedTextField the cpfjFormattedTextField to set
     */
    public void setCpfjFormattedTextField(String str) {
        this.cpfjFormattedTextField.setText(str);
    }

    /**
     * @param criarUsrjCheckBox the criarUsrjCheckBox to set
     */
    public void setCriarUsrjCheckBox(boolean b) {

        if (!b) {
            criarUsrjCheckBox.setSelected(false);
            jPanel1.setVisible(false);

        } else {
            criarUsrjCheckBox.setSelected(true);
            jPanel1.setVisible(true);

        }
    }

    /**
     * @param dataadmjFormattedTextField1 the dataadmjFormattedTextField1 to set
     */
    public void setDataadmjFormattedTextField1(String str) {
        this.dataadmjFormattedTextField1.setText(str);
    }

    /**
     * @param datajFormattedTextField the datajFormattedTextField to set
     */
    public void setDatajFormattedTextField(String str) {
        this.datajFormattedTextField.setText(str);
    }

    /**
     * @param jPasswordField1 the jPasswordField1 to set
     */
    public void setjPasswordField1(String str) {
        this.jPasswordField1.setText(str);
    }

    /**
     * @param jPasswordField2 the jPasswordField2 to set
     */
    public void setjPasswordField2(String str) {
        this.jPasswordField2.setText(str);
    }

    /**
     * @param lojajComboBox the lojajComboBox to set
     */
    public void setLojajComboBox(int s) {
        lojajComboBox.setSelectedIndex(s - 1);
    }

    /**
     * @param nomejTextField the nomejTextField to set
     */
    public void setNomejTextField(String str) {
        this.nomejTextField.setText(str);
    }

    /**
     * @param rgjTextField the rgjTextField to set
     */
    public void setRgjTextField(String str) {
        this.rgjTextField.setText(str);
    }
}
